/**
 * Copyright(c) 2013 Jade Techonologies Co., Ltd.
 *
 * History:
 *   13-4-14 下午3:59 Created by dwzhang
 */
package com.jade.framework.base.criterion.expression;

/**
 * Constrains the property to a specified list of values.
 *
 * @author dwzhang
 * @version 1.0 13-4-14 下午3:59
 */
public class InExpression extends AbstractPropertyExpression
{
    protected final Object[] values;

    /**
     * 构造函数.
     *
     * @param entityName 实体名称
     * @param propName   属性名称
     * @param values     取值范围
     */
    public <T> InExpression(String entityName, String propName, T... values)
    {
        super(entityName, propName);
        this.values = values;
    }

    /**
     * 构造函数.
     *
     * @param propName 属性名
     * @param values   取值范围.
     */
    public <T> InExpression(String propName, T... values)
    {
        super(propName);
        this.values = values;
    }

    public Object[] getValues()
    {
        return values;
    }

    protected String getPrefix()
    {
        return "IN";
    }

    @Override
    public String toString()
    {
        StringBuilder sb = new StringBuilder();
        sb.append(getFullName());
        sb.append(" ").append(getPrefix());
        sb.append("(");
        for (int i = 0; i < values.length; i++) {
            if (i > 0) {
                sb.append(",");
            }
            sb.append(values[i]);
        }
        sb.append(")");
        return sb.toString();
    }
}
